<?php           
 $topNestedModule = $this->module; while (!is_null($topNestedModule->parentModule)) $topNestedModule = $topNestedModule->parentModule; ?>

<link rel="stylesheet" href="<?php echo $topNestedModule->assetsUrl; ?>/css/hq.css">
<link rel="stylesheet" href="<?php echo $topNestedModule->assetsUrl; ?>/css/nav.css">
<?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>

<?php
	$menus = array(
		'News'			=>	array(
			'Categories'	=> '/hq/category',
			'News'			=> '/hq/news',
		),

		'User'				=>	array(
			'User'			=>	'/hq/user',
		),

	);
?>

<script language="JavaScript">
<!--
jQuery(function($) {
	$('.treeview a').each(function (e) {
		$(this).click(function (e) {
			e.preventDefault();

			parent.location = $(this).attr('href');

			return false;
		})
	});
});
//-->
</script>

<ul class="treeview">
<?php foreach ($menus as $mName => $controllers): ?>
	<li>
		<?php echo $mName; ?>
		<ul>
		<?php foreach ($controllers as $label => $route): ?>
			<li class="leaf"><a href="<?php echo $this->createUrl($route); ?>"><?php echo $label ?></a></li>
		<?php endforeach; ?>
		</ul>
	</li>
<?php endforeach; ?>
</ul>

<?php return; ?>

<?php
	$tree = array();

	$buildTree = function($menus, & $tree, $recursiveFunc) {
		foreach ($menus as $name => $info) {

			$node = array(
				'text'		=>	is_string($info) ? CHtml::link($name, Yii::app()->controller->createUrl($info)) : $name,
				'expanded'  =>	true,
				'htmlOptions'	=>	array(
					'class'	=>	is_string($info) ? 'leaf' : '',
				),
			);

			if (is_array($info)) {
				$node['hasChildren'] = true;
				$node['children'] = array();

				$recursiveFunc($info, $node['children'], $recursiveFunc);
			}

			$tree[] = & $node;

			unset($node);
		}
	};

	$buildTree($menus, $tree, $buildTree);
?>

<?php
	$this->widget('CTreeView',array(
        'data'		=> $tree,
        'animated'	=>'fast', //quick animation
        'collapsed'	=>'false',//remember must giving quote for boolean value in here
        'persist'	=>	'cookie',
        'htmlOptions'=>array(
                'class'=>'treeview-famfamfam',//there are some classes that ready to use
        ),
	));
?>

<?php #Yii::app()->clientScript->registerScriptFile($this->module->assetsUrl . '/scripts/jquery-iframe-resizer.js'); ?>
